﻿var SCA = SCA || {};
SCA.UI = SCA.UI || {};
SCA.UI.DocumentTemplates = SCA.UI.DocumentTemplates || {};

SCA.UI.DocumentTemplates.Table = function () {

    this.AddRow = function (index) {
        var lastTr = jQuery('#TableDocumentTemplates tr:last');
        var rowHtml = '<tr id="TRTableDocumentTemplates' + index + '">\
                            <td>\
                                <input type="button" value="Edit" class="template-edit-button" onclick="OpenDocumentTemplatesDialog(\'' + index + '\')"/>\
                                <input type="button" value="Delete" class="sbs-button" onclick="mainUI.documentTemplatesTable.DeleteRow(\'' + index + '\')"/>\
                            </td>\
                            <td id="TDTableDocumentTemplates'+ index + '_1">\
                                ' + SCA.AppConfiguration.DocumentTemplates[index].ApplicationType +
                            '</td>\
                            <td id="TDTableDocumentTemplates' + index + '_2">\
                                ' + SCA.AppConfiguration.DocumentTemplates[index].Title +
                            '</td>\
                      </tr>';
        lastTr.after(rowHtml);
    }

    this.DeleteRow = function (index) {
        jQuery("#TRTableDocumentTemplates" + index).hide();
        SCA.AppConfiguration.DocumentTemplates[index].IsDeleted = true;
    }

    this.RefreshRow = function (index) {
        jQuery("#TDTableDocumentTemplates" + index + "_1").html(SCA.AppConfiguration.DocumentTemplates[index].ApplicationType);
        jQuery("#TDTableDocumentTemplates" + index + "_2").html(SCA.AppConfiguration.DocumentTemplates[index].Title);
    }
};